package com.ssm.student.service.impl;

import com.ssm.student.dao.StudentMapper;
import com.ssm.student.model.Student;
import com.ssm.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *实现业务及流程当中的内容
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

   @Override
    public int AddStudent(Student student) {
        int returnInt=0;
        /*1.业务判断
        （1）学生学号不能重复

        （1）判断学生
        * */
        int snoCount=0;
        snoCount= studentMapper.getSno(student.getSno());
        if (snoCount<1){
            //2.数据添加
            int addStudentInt= studentMapper.insertStudent(student);
            //3.返回值设置
            returnInt=addStudentInt;

        }else {
            returnInt=-1;//有相同的学生学号
        }
        return returnInt;
    }


    @Override
    public int updateStudent(Student student) {
        int isUpdate=0;
        /*1.没有业务流程的判断*/
        try{
            isUpdate=studentMapper.updateStudent(student);
        }catch (Exception e){
            isUpdate=-1;
            //打印更新报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因"+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int delStudent(int studentid) {
        int delStudent=0;
        /*1.有关业务流程的判断
         * (1)删除的角色不能与人员权限中间表有关联*/
        try {
            //返回的结果总数量小于1才可以删除

        }catch (Exception e){

            System.out.println("删除角色信息时执行SQL报错原因为"+e.getMessage());
        }
        return delStudent;
    }
}

